<?php

use yii\db\Migration;

class m170829_075234_orders_item_relation extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%orders_items_relation}}', 'type', $this->string(10) . ' default null comment \'转化（conversion）,续费（renew）\'');
            $this->addColumn('{{%orders_items_relation}}', 'customer_id', $this->integer() . ' default 0 comment \'会员id\'');
            $this->addColumn('{{%orders_items_relation}}', 'student_id', $this->integer() . ' default 0 comment \'学员id\'');
            $this->addColumn('{{%orders_items_relation}}', 'goods_id', $this->integer() . ' default 0 comment \'课程id\'');
            $this->addColumn('{{%orders_items_relation}}', 'teach_type', $this->smallInteger(2) . ' default 1 comment \'1 技教学 2 艺教学\'');
        }

    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%orders_items_relation}}', 'type');
            $this->dropColumn('{{%orders_items_relation}}', 'customer_id');
            $this->dropColumn('{{%orders_items_relation}}', 'student_id');
            $this->dropColumn('{{%orders_items_relation}}', 'goods_id');
            $this->dropColumn('{{%orders_items_relation}}', 'teach_type');
        }
    }

}
